#ifndef SENS_RECEIVER
#define SENS_RECEIVER

#ifdef  __cplusplus
extern "C" {
#endif

/* The sensor data available to the callback function */
typedef struct _sens_data {
  double x;
  double y;
  double z;
  unsigned int keys;
  double timestamp; 
  unsigned int devid;
} tsens_data;

/* type of the callback function */
typedef int (* tsens_callback)(tsens_data);

/* the default port for receiving filtered sensor data */
#define SENS_PORT 9642

/* the maximal number of parallel connections */
#define MAX_CON 10

/* open the connection to receive sensor data and register callback */
extern int sens_open(int port, tsens_callback callback);

/* receive one packet and call registered callback, blocking */
extern int receive_one(int port);

/* threaded version */
extern int start_receiving(int port);
extern int is_receiving(int port);
extern int stop_receiving(int port);
extern void get_open_ports(int ports[MAX_CON]);

/* close the connection, not really necessary */
extern int sens_close(int port);

/* threadsafe polling; but then don't use anything else and just one port*/
extern int start_polling(int port);
extern tsens_data sens_poll(int port); /* use that to retrieve latest available packet */
extern int stop_polling(int port);

/* sample callback that prints the contents of a packet to stdout */
extern void show_sens_data(tsens_data sens_data);

/* the keycodes */
#define KEY_UP    0x00000001
#define KEY_DOWN  0x00000002
#define KEY_LEFT  0x00000004
#define KEY_RIGHT 0x00000008
#define KEY_FIRE  0x00000010
#define KEY_0     0x00000100
#define KEY_1     0x00000200
#define KEY_2     0x00000400
#define KEY_3     0x00000800
#define KEY_4     0x00001000
#define KEY_5     0x00002000
#define KEY_6     0x00004000
#define KEY_7     0x00008000
#define KEY_8     0x00010000
#define KEY_9     0x00020000
#define KEY_STAR  0x00040000
#define KEY_HASH  0x00080000

#ifdef  __cplusplus
}
#endif

#endif

